<?php
class AppHtmlHelper extends HtmlHelper {

	function nl2br($data) {
		if (is_array($data)) {
			$filtered = array ();
			foreach ($data as $key => $value) {
				$data[$key] = nl2br($value);
			}
		} else {
			$data = nl2br($data);
		}
		return $data;
	}

	function calendar($fieldName, $format = '%Y-%m-%d', $htmlAttributes = null, $return = false) {
		$this->setFormTag($fieldName);
		if (!isset ($htmlAttributes['value'])) {
			$htmlAttributes['value'] = $this->tagValue($fieldName);
		}

		if (!isset ($htmlAttributes['type'])) {
			$htmlAttributes['type'] = 'text';
		}

		if (!isset ($htmlAttributes['size'])) {
			$htmlAttributes['size'] = '10';
		}

		if (!isset ($htmlAttributes['id'])) {
			$htmlAttributes['id'] = $this->model . Inflector :: camelize($this->field);
		}

		$script = "
					<img align=\"top\" style=\"cursor:hand\" src=\"/js/calendar/calendar.gif\" id=\"" . $htmlAttributes['id'] . "-button\"/>
				    <script type=\"text/javascript\">
						Calendar.setup({ 
						 inputField :  '" . $htmlAttributes['id'] . "', 
						 ifFormat :    '" . $format . "', 
						 button :      '" . $htmlAttributes['id'] . "-button', 
						 align :       'cr', 
						 singleClick : true, 
						 firstDay :    1
						});
					</script>";

		if ($this->tagIsInvalid($this->model, $this->field)) {
			if (isset ($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
				$htmlAttributes['class'] .= ' form_error';
			} else {
				$htmlAttributes['class'] = 'form_error';
			}
		}
		return $this->output(sprintf($this->tags['calendar'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' '), $script) . $script, $return);
	}

	/**
	 * Creates a set of checkbox widgets.
	 *
	 * @param  string  $fieldName      Name of a field, like this "Modelname/fieldname"
	 * @param  array    $values		   Checkbox values array
	 * @param  array    $titles		   Checkbox titles array
	 * @param  array    $checked	   Checkbox checked array
	 * @param  array    $htmlAttributes Array of HTML attributes.
	 * @param  array    $inbetween	   String that separates the checkboxes.
	 * @param  boolean $return         Wheter this method should return a value
	 *                                 or output it. This overrides AUTO_OUTPUT.
	 * @return mixed    Either string or boolean value, depends on AUTO_OUTPUT
	 *                 and $return.
	 */
	function checkboxes($fieldName, $options, $inbetween = null, $htmlAttributes = array (), $return = false, $brnum = 3 ,$displayTextList = null) {
		$this->setFormTag($fieldName);
		list ($model, $field) = explode("/", $fieldName);
		if (isset ($this->params['data'][$model][$field])) {
			$value = ($this->params['data'][$model][$field]);
		}
		elseif (isset ($this->data[$model][$field])) {
			$value = ($this->data[$model][$field]);
		}
		$value = isset ($value) ? $value : array ();
		$out = array ();

		$loop = 0;
		foreach ($options as $optValue => $optTitle) {
			$displayText=false;
			if(!empty($displayTextList) && in_array($optValue,$displayTextList)){
				$displayText=true;
			}
			$loop += 1;
			$optionsHere = array (
				'value' => $optValue
			);
			in_array($optValue, $value) ? $optionsHere['checked'] = 'checked' : null;
			$displayText==true ? $optionsHere['onclick'] = "javascript:enableOtherText(this,'".$this->model.Inflector::camelize($this->field.'_other')."')" : null;
			$parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
			$individualTagName = "{$this->field}_{$optValue}";
			$out[] = sprintf($this->tags['checkboxes'], $this->model, $this->field, $individualTagName, $parsedOptions, '&nbsp;'.$optTitle.'&nbsp;&nbsp;&nbsp;');
			if($displayText){
				if($optValue == $value){
					$this->input($fieldName.'_other');
				}else{
					$this->input($fieldName.'_other',array('disabled'=>'disabled'));
				}
			}
			if(!empty($brnum)){
				if ($loop % $brnum == 0) {
					$out[] = sprintf("<br/>");
				}				
			}
		}

		$out = join($inbetween, $out);
		return $this->output($out ? $out : null, $return);
	}
	
	function checkboxes1($fieldName, $options, $inbetween = null, $htmlAttributes = array (), $return = false, $brnum = 3 ,$displayTextList = null) {
		$this->setFormTag($fieldName);
		list ($model, $field) = explode("/", $fieldName);
		if (isset ($this->params['data'][$model][$field])) {
			$value = ($this->params['data'][$model][$field]);
		}
		elseif (isset ($this->data[$model][$field])) {
			$value = ($this->data[$model][$field]);
		}
		$value = isset ($value) ? $value : array ();
		$out = array ();
        $out[]=sprintf("<table width=450px; border=0 class=\"\"><tr>");
		$loop = 0;
		$colcount=1;
		foreach ($options as $optValue => $optTitle) {
			$displayText=false;
			if(!empty($displayTextList) && in_array($optValue,$displayTextList)){
				$displayText=true;
			}
			$loop += 1;
			$optionsHere = array (
				'value' => $optValue
			);
			in_array($optValue, $value) ? $optionsHere['checked'] = 'checked' : null;
			$displayText==true ? $optionsHere['onclick'] = "javascript:enableOtherText(this,'".$this->model.Inflector::camelize($this->field.'_other')."')" : null;
			$parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
			$individualTagName = "{$this->field}_{$optValue}";
			$out[] = sprintf("<td>");
			$out[] = sprintf($this->tags['checkboxes'], $this->model, $this->field, $individualTagName, $parsedOptions, '&nbsp;'.$optTitle.'&nbsp;&nbsp;&nbsp;');
			$out[] = sprintf("</td>");
			if($displayText){
				if($optValue == $value){
					$this->input($fieldName.'_other');
				}else{
					$this->input($fieldName.'_other',array('disabled'=>'disabled'));
				}
			}
			if(!empty($brnum)){
				if ($loop % $brnum == 0&&$loop!=count($options)) {
					$out[] = sprintf("</tr><tr>");
					$colcount++;
				}				
			}			
		}
		if(count($options)<$brnum*$colcount){
			for($i=0;$i<$brnum*$colcount-count($options);$i++){
				$out[]=sprintf("<td></td>");
			}
		}
        $out[]=sprintf("</tr></table>");
		$out = join($inbetween, $out);
		return $this->output($out ? $out : null, $return);
	}
    
	function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array (), $return = false, $countInLine = 3, $displayTextList=null) {
		$value = isset ($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->tagValue($fieldName);
		$out = array ();

		$loop = 0;
		foreach ($options as $optValue => $optTitle) {
			$displayText=false;
			if(!empty($displayTextList) && in_array($optValue,$displayTextList)){
				$displayText=true;
			}
			$loop += 1;
			$optionsHere = array (
				'value' => $optValue
			);
			$optValue == $value ? $optionsHere['checked'] = 'checked' : null;
			$displayText==true ? $optionsHere['onclick'] = "javascript:enableOtherText(this,'".$this->model.Inflector::camelize($this->field.'_other')."')" : null;
			$parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
			$individualTagName = "{$this->field}_{$optValue}";
			$out[] = sprintf($this->tags['radio'], $this->model, $this->field, $individualTagName, $parsedOptions, '&nbsp;'.$optTitle.'&nbsp;&nbsp;&nbsp;');
			if($displayText){
				if($optValue == $value){
					$this->input($fieldName.'_other');
				}else{
					$this->input($fieldName.'_other',array('disabled'=>'disabled'));
				}
			}
			if ($loop % $countInLine == 0) {
				$out[] = sprintf("<br/>");
			}
		}

		$out = join($inbetween, $out);
		return $this->output($out ? $out : null, $return);
	}

	function yearDbOptionTag($tagName, $value = null, $minYear = null, $maxYear = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_year");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$yearValue = empty ($selected) && !$showEmpty ? date('Y') : $selected;
		$currentYear = date('Y');
		$year = & new Year();
		$years = $year->generateList('deleted is null');

		$option = $this->selectTag($tagName . "_year", $years, $yearValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}
	function monthDbOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_month");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$monthValue = empty ($selected) && !$showEmpty ? date('m') : $selected;
		$month = & new Month();
		$months = $month->generateList('deleted is null');

		$option = $this->selectTag($tagName . "_month", $months, $monthValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}
	function dayDbOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_day");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$dayValue = empty ($selected) && !$showEmpty ? date('d') : $selected;
		$day = & new Day();
		$days = $day->generateList('deleted is null');

		$option = $this->selectTag($tagName . "_day", $days, $dayValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}

	function yearOptionTag($tagName, $value = null, $minYear = null, $maxYear = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_year");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$yearValue = empty ($selected) && !$showEmpty ? date('Y') : $selected;
		$currentYear = date('Y');
		$maxYear = is_null($maxYear) ? $currentYear +11 : $maxYear +1;
		$minYear = is_null($minYear) ? $currentYear -60 : $minYear;

		if ($minYear > $maxYear) {
			$tmpYear = $minYear;
			$minYear = $maxYear;
			$maxYear = $tmpYear;
		}

		$minYear = $currentYear < $minYear ? $currentYear : $minYear;
		$maxYear = $currentYear > $maxYear ? $currentYear : $maxYear;

		for ($yearCounter = $minYear; $yearCounter < $maxYear; $yearCounter++) {
			$years[$yearCounter] = $yearCounter;
		}

		$option = $this->selectTag($tagName . "_year", $years, $yearValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}
	function monthOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_month");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$monthValue = empty ($selected) && !$showEmpty ? date('m') : $selected;
		$months = array (
			'01' => '01',
			'02' => '02',
			'03' => '03',
			'04' => '04',
			'05' => '05',
			'06' => '06',
			'07' => '07',
			'08' => '08',
			'09' => '09',
			'10' => '10',
			'11' => '11',
			'12' => '12'
		);

		$option = $this->selectTag($tagName . "_month", $months, $monthValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}
	function dayOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_day");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$dayValue = empty ($selected) && !$showEmpty ? date('d') : $selected;
		$days = array (
			'01' => '01',
			'02' => '02',
			'03' => '03',
			'04' => '04',
			'05' => '05',
			'06' => '06',
			'07' => '07',
			'08' => '08',
			'09' => '09',
			'10' => '10',
			'11' => '11',
			'12' => '12',
			'13' => '13',
			'14' => '14',
			'15' => '15',
			'16' => '16',
			'17' => '17',
			'18' => '18',
			'19' => '19',
			'20' => '20',
			'21' => '21',
			'22' => '22',
			'23' => '23',
			'24' => '24',
			'25' => '25',
			'26' => '26',
			'27' => '27',
			'28' => '28',
			'29' => '29',
			'30' => '30',
			'31' => '31'
		);
		$option = $this->selectTag($tagName . "_day", $days, $dayValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}

	function hourOptionTag($tagName, $value = null, $format24Hours = false, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_hour");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		if ($format24Hours) {
			$hourValue = !isset ($selected) && !$showEmpty ? date('H') : $selected;
		} else {
			$hourValue = !isset ($selected) && !$showEmpty ? date('g') : $selected;
			if (intval($hourValue) == 0) {
				$hourValue = 12;
			}
		}

		if ($format24Hours) {
			$hours = array (
				'00' => '00',
				'01' => '01',
				'02' => '02',
				'03' => '03',
				'04' => '04',
				'05' => '05',
				'06' => '06',
				'07' => '07',
				'08' => '08',
				'09' => '09',
				'10' => '10',
				'11' => '11',
				'12' => '12',
				'13' => '13',
				'14' => '14',
				'15' => '15',
				'16' => '16',
				'17' => '17',
				'18' => '18',
				'19' => '19',
				'20' => '20',
				'21' => '21',
				'22' => '22',
				'23' => '23'
			);
		} else {
			$hours = array (
				'01' => '1',
				'02' => '2',
				'03' => '3',
				'04' => '4',
				'05' => '5',
				'06' => '6',
				'07' => '7',
				'08' => '8',
				'09' => '9',
				'10' => '10',
				'11' => '11',
				'12' => '12'
			);
		}

		$option = $this->selectTag($tagName . "_hour", $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}
	function minuteOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$tagValue = $this->tagValue($tagName . "_min");
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}
		$minValue = !isset ($selected) && !$showEmpty ? date('i') : $selected;

		for ($minCount = 0; $minCount < 60; $minCount++) {
			$mins[sprintf('%02d', $minCount)] = sprintf('%02d', $minCount);
		}
		$option = $this->selectTag($tagName . "_min", $mins, $minValue, $selectAttr, $optionAttr, $showEmpty);
		return $option;
	}

	function dateTimeOptionTag($tagName, $dateFormat = 'YMD', $timeFormat = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = false) {
		$day = null;
		$month = null;
		$year = null;
		$hour = null;
		$min = null;
		$meridian = null;

		$tagValue = $this->tagValue($tagName);
		if (!empty ($tagValue)) {
			$selected = $tagValue;
		}

		if (!empty ($selected)) {

			if (is_int($selected)) {
				$selected = strftime('%G-%m-%d  %T', $selected);
				$selected = strftime('%G-%m-%d  %H:%M:%S', $selected);
			}

			$meridian = 'am';
			$pos = strpos($selected, '-');
			if ($pos !== false) {
				$date = explode('-', $selected);
				$days = explode(' ', $date[2]);
				$day = $days[0];
				$month = $date[1];
				$year = $date[0];
			} else {
				$days[1] = $selected;
			}

			if ($timeFormat != 'NONE' && !empty ($timeFormat)) {
				$time = explode(':', $days[1]);

				if (($time[0] > 12) && $timeFormat == '12') {
					$time[0] = $time[0] - 12;
					$meridian = 'pm';
				}
				elseif ($time[0] > 12) {
					$meridian = 'pm';
				}

				$hour = $time[0];
				$min = $time[1];
			}
		}

		$elements = array (
			'Day',
			'Month',
			'Year',
			'Hour',
			'Minute',
			'Meridian'
		);
		if (isset ($selectAttr['id'])) {
			if (is_string($selectAttr['id'])) {
				// build out an array version
				foreach ($elements as $element) {
					$selectAttrName = 'select' . $element . 'Attr';
					${ $selectAttrName } = $selectAttr;
					${ $selectAttrName }['id'] = $selectAttr['id'] . $element;
				}
			}
			elseif (is_array($selectAttr['id'])) {
				// check for missing ones and build selectAttr for each element
				foreach ($elements as $element) {
					$selectAttrName = 'select' . $element . 'Attr';
					${ $selectAttrName } = $selectAttr;
					${ $selectAttrName }['id'] = $selectAttr['id'][strtolower($element)];
				}
			}
		} else {
			// build the selectAttrName with empty id's to pass
			foreach ($elements as $element) {
				$selectAttrName = 'select' . $element . 'Attr';
				${ $selectAttrName } = $selectAttr;
			}
		}

		switch ($dateFormat) {
			case 'DMY' : // so uses the new selex
				$opt = $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' .
				$this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
				break;
			case 'MDY' :
				$opt = $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
				$this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
				break;
			case 'YMD' :
				$opt = $this->yearOptionTag($tagName, null, 2001, 2023, $year, $selectYearAttr, $optionAttr, $showEmpty) . ' 年 ' .
				$this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . ' 月 ' .
				$this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . ' 日 ';
				break;
			case 'NONE' :
			default :
				$opt = '';
				break;
		}

		switch ($timeFormat) {
			case '24' :
				$opt .= $this->hourOptionTag($tagName, null, true, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
				$this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty);
				break;
			case '12' :
				$opt .= $this->hourOptionTag($tagName, null, false, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
				$this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty) . ' ' .
				$this->meridianOptionTag($tagName, null, $meridian, $selectMeridianAttr, $optionAttr, $showEmpty);
				break;
			case 'NONE' :
			default :
				$opt .= '';
				break;
		}
		return $opt;
	}

	/**
	 * Creates a formatted IMG element.
	 *
	 * @param string $path Path to the image file, relative to the webroot/img/ directory.
	 * @param array	$htmlAttributes Array of HTML attributes.
	 * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
	 * @return mixed	Either string or boolean value, depends on AUTO_OUTPUT and $return.
	 */
	function image($path, $htmlAttributes = null, $return = false) {

		$path = str_replace("\\", "/", $path);

		if (strpos($path, '://')) {
			$url = $path;
		} else {
			$url = $this->webroot . $path;
		}
		return $this->output(sprintf($this->tags['image'], $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);

	}
	
	function imagefile($fieldName, $htmlAttributes = null, $del_btn = true) {
		$output = '';
		if (strpos($fieldName, '/')) {
			$this->setFormTag($fieldName);
			$output .= $this->fileTag($this->field . '_file[]');
			if($del_btn){
				$output .= $this->checkbox($fieldName . '_del');
				$output .= '削除<br/>';				
			}

			$image_path = $this->tagValue($fieldName . '_path');
			if (!empty ($image_path)) {
				$output .= $this->image($image_path);
				$output .= $this->hidden($fieldName . '_path');
			}
			$output .= $this->hidden($fieldName);
		}

		return $output;
	}

	function linkbutton($title, $url = null, $htmlAttributes = null, $confirmMessage = false, $escapeTitle = true, $return = false) {
		if ($escapeTitle) {
			$title = htmlentities($title, ENT_QUOTES);
		}
		$url = $url ? $url : $title;

		if ($confirmMessage) {
			$confirmMessage = htmlentities($confirmMessage, ENT_NOQUOTES);
			$confirmMessage = str_replace("'", "\'", $confirmMessage);
			$confirmMessage = str_replace('"', '&quot;', $confirmMessage);
			$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
		}

		if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0))) {
			$output = sprintf($this->tags['linkbutton'], $title, $url, $this->_parseAttributes($htmlAttributes));
		} else {
			$output = sprintf($this->tags['linkbutton'], $title, $this->url($url, true), $this->_parseAttributes($htmlAttributes), $title);
		}
		return $this->output($output, $return);
	}

	function filter($data) {
		$search = array (
			'@&@',
			'@"@',
			'@\'@',
			'@<@',
			'@>@'
		); // evaluate as php

		$replace = array (
			'&amp;',
			'&quot;',
			'&#039;',
			'&lt;',
			'&gt;'
		);
		if (is_array($data)) {
			$filtered = array ();
			foreach ($data as $key => $value) {
				$data[$key] = preg_replace($search, $replace, $value);
			}
		} else {
			$data = preg_replace($search, $replace, $data);
		}
		return $data;
	}

	function toUpCase($data) {
		$search = array (
			'@a@',
			'@b@',
			'@c@',
			'@d@',
			'@e@',
			'@f@',
			'@g@',
			'@h@',
			'@i@',
			'@j@',
			'@k@',
			'@l@',
			'@m@',
			'@n@',
			'@o@',
			'@p@',
			'@q@',
			'@r@',
			'@s@',
			'@t@',
			'@u@',
			'@v@',
			'@w@',
			'@x@',
			'@y@',
			'@z@'
		);

		$replace = array (
			'A',
			'B',
			'C',
			'D',
			'E',
			'F',
			'G',
			'H',
			'I',
			'J',
			'K',
			'L',
			'M',
			'N',
			'O',
			'P',
			'Q',
			'R',
			'S',
			'T',
			'U',
			'V',
			'W',
			'X',
			'Y',
			'Z'
		);
		if (is_array($data)) {
			$filtered = array ();
			foreach ($data as $key => $value) {
				$data[$key] = preg_replace($search, $replace, $value);
			}
		} else {
			$data = preg_replace($search, $replace, $data);
		}
		return $data;
	}

	function subString($data, $length) {
		$data = $this->filter($data);
		if (mb_strlen($data,'UTF-8') > $length) {
			$data = mb_substr($data, 0, $length,'UTF-8') . '...';
		}
		return $data;
	}
	
	function tagFilter($data) {
		$search = array (
			'#<%(.*)%>|#',
			'#<[a-zA-Z]+?.*?>|#is'
		);
		$replace = '';
		if (is_array($data)) {
			$filtered = array ();
			foreach ($data as $key => $value) {
				$data[$key] = preg_replace($search, $replace, $value);
			}
		} else {
			$data = preg_replace($search, $replace, $data);
		}
		return $data;
	}
	
	function encryptData($encrypt,$data,$other=array()){
		$encrypt->decode($data);
		
		if(empty($other)){
			return $data;
		}
		
		foreach($other as $key => $val){
			if($val=='filter'){
				$data = $this->filter($data);
			}
			if($val=='nl2br'){
				$data = $this->nl2br($data);
			}
			if($key=='subString'&&!empty($val)){
				$this->subString($data,$val);
			}
			return $data;
		}
	}
	
	function getFloor($company_id){
		return floor($company_id/1000);
	}
	
	function printArray($data){
		if(!is_array($data)){
			return $data;
		}
		$arr = array();
		foreach ($data as $d){
			$arr[] = $d['SysParams']['name'];
		}
		return implode(',',$arr);
	}
	
	/**
	 * @auth yangjie
	 * @desc 输出求人情报的ICON
	 */
	function printIcon($job_data){
		if(isset($job_data['JobHopeLanguage'])&&!empty($job_data['JobHopeLanguage'])){
			foreach($job_data['JobHopeLanguage'] as $d){
				if($d['hope_language_id']==1){
					echo "<img src=\"/images/state/jp.gif\"/>";
				}
				if($d['hope_language_id']==2){
					echo "<img src=\"/images/state/ch.gif\"/>";
				}
				if($d['hope_language_id']==3){
					echo "<img src=\"/images/state/en.gif\"/>";
				}
				
			}
		}
		if(isset($job_data['JobHopeMember'])&&!empty($job_data['JobHopeMember'])){
			foreach($job_data['JobHopeMember'] as $d){
				if($d['hope_member_id']==1){
					echo "<img src=\"/images/state/newman.gif\"/>";
				}
				if($d['hope_member_id']==2){
					echo "<img src=\"/images/state/bg.gif\"/>";
				}
				if($d['hope_member_id']==3){
					echo "<img src=\"/images/state/s.gif\"/>";
				}
			}
		}
		if(isset($job_data['JobAttention'])&&!empty($job_data['JobAttention'])){
			foreach($job_data['JobAttention'] as $d){
				if($d['attention_id']==1){
					echo "<img src=\"/images/state/g.gif\"/>";
				}
				if($d['attention_id']==2){
					echo "<img src=\"/images/state/b.gif\"/>";
				}
				if($d['attention_id']==3){
					echo "<img src=\"/images/state/zero.gif\"/>";
				}
			}
		}
	}
	
}
?>